#ifndef __STACK_QUEUE_H__
#define __STACK_QUEUE_H__

#include "myStack.h"

template<class Type>
class SQueue {
public:
	SQueue() { }
	~SQueue();

	bool push(Type val);
	bool pop();

	size_t size();
	bool empty();
	bool clear();

	Type front();
	Type back();

private:
	MyStack<Type> push_stack_;
	MyStack<Type> pop_stack_;
	Type last_elem_;
};

template<class Type>
SQueue<Type>::~SQueue() {
	push_stack_.clear();
	pop_stack_.clear();
}

template<class Type>
bool SQueue<Type>::push(Type val) {
	last_elem_ = val;
	return push_stack_.push(val);
}

template<class Type>
bool SQueue<Type>::pop() {
	if (pop_stack_.size() == 0) {
		while (!push_stack_.empty()) {
			Type val = push_stack_.top();
			push_stack_.pop();
			pop_stack_.push(val);
		}
	}
	return pop_stack_.pop();
}

template<class Type>
Type SQueue<Type>::front() {
	if (pop_stack_.size() == 0) {
		while (!push_stack_.empty()) {
			Type val = push_stack_.top();
			push_stack_.pop();
			pop_stack_.push(val);
		}
	}

	return pop_stack_.top();
}

template<class Type>
Type SQueue<Type>::back() {
	return last_elem_;
}

template<class Type>
size_t SQueue<Type>::size() {
	return push_stack_.size() + pop_stack_.size();
}

template<class Type>
bool SQueue<Type>::empty() {
	return push_stack_.empty() && pop_stack_.empty();
}

template<class Type>
bool SQueue<Type>::clear() {
	return push_stack_.clear() && pop_stack_.clear();
}

#endif

